package com.sui.bigdata.sml.web.repository.mapper;

import com.sui.bigdata.sml.web.repository.model.Component;
import com.sui.bigdata.sml.web.repository.model.ComponentCategory;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author songhaicheng
 * @date 2019/11/5 10:00
 * @description
 * @reviewer
 */
@Repository
public interface ComponentMapper {

    @Insert("insert into component(name,category_id,in_port,out_port,rules,alg_class_name) " +
            "values(#{name},#{categoryId},#{inPort},#{outPort},#{rules},#{algClassName})")
    @Options(useGeneratedKeys = true)
    int insert(Component component);

    @Select("select * from component where id=#{id}")
    Component get(Long id);

    @Update("update component set name=#{name},category_id=#{categoryId},in_port=#{inPort},out_port=#{outPort}," +
            "rules=#{rules},alg_class_name=#{algClassName} where id=#{id}")
    int update(Component component);

    @Select("select * from component")
    List<Component> list();

    @Delete("delete from component where id=#{id}")
    int delete(Long id);

    @Select("select * from component_category")
    List<ComponentCategory> listCategories();

    @Insert("insert into component_category(name,parent_category_id,icon) " +
            "values(#{name},#{parentCategoryId},#{icon})")
    @Options(useGeneratedKeys = true)
    int insertCategory(ComponentCategory componentCategory);

    @Select("select * from component_category where id=#{id}")
    Component getCategory(Integer id);

    @Update("update component_category set name=#{name},parent_category_id=#{parentCategoryId},icon=#{icon} where id=#{id}")
    int updateCategory(ComponentCategory componentCategory);

}
